home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / Technical Documentation / develop / develop Issue 24 / develop Issue 24 code / Scriptable Database 1.0a15 / Base / Debug.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-19  |  3.9 KB  |  134 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Debug.h
  3.  
  4.     Contains:    Simple debug macros for use with debug window.
  5.  
  6.     Usage:
  7.                 You need extra parentheses since this is done with the preprocessor
  8.                  e.g. PRINT(("hello world..."))
  9.  
  10.     Written by:    Bruce Horn, Steve Capps, Larry Kenyon,
  11.                 John Meier, scott douglass, Darin Adler,
  12.                 Paul Mercer, Bryan Stearns, Dave Owens,
  13.                 Jeff Miller
  14.  
  15.     Copyright:    © 1988-1990, 1993-1994 by Apple Computer, Inc., all rights reserved.
  16.  
  17.                  2/23/95    ga        
  18.         <11>    10/13/94    ga        
  19. */
  20.  
  21. #ifndef Debug_h
  22. #define Debug_h
  23.  
  24. //
  25. // It would be better to set this in some sort of
  26. // build-configuration file, but MW doesn't conveniently
  27. // support that at the moment.
  28. //
  29. #define DEBUG 1
  30.  
  31.  
  32. #include <Types.h>
  33.  
  34. // actual debug functions and macros
  35.  
  36. extern void dbgAssertPrint(const char*, ...);
  37. extern void dbgAssert(const char* filename, SInt32 line);
  38. extern void dbgGuard(const char* filename, SInt32 line);
  39. extern void dbgInvalidPointer(const void* pointer, const char* filename, SInt32 line);
  40. extern void dbgInvalidHandle(const void** handle, const char* filename, SInt32 line);
  41.  
  42.  
  43. #ifdef DEBUG
  44.  
  45. #define INLINEASSERT(what)                 { if (!(what)) Debugger(); }
  46.  
  47. #define INITIALIZEDEBUG()
  48. #define TERMINATEDEBUG()
  49. #define DEBUGEVENT(event)
  50.  
  51. #define BLOCKPRINT(args)                { dbgAssertPrint args; }
  52. #define PRINT(args)                        do BLOCKPRINT(args) while (0)
  53. #define CAPSPRINT(args)                    ASSERTPRINT(!CapsLockCurrentlyDown(), args)
  54.  
  55. #define BLOCKPRINTNOT(what, args)        { if (what) { dbgAssertPrint args; } }
  56. #define PRINTNOT(what, args)            do BLOCKPRINTNOT(what, args) while (0)
  57. #define CAPSPRINTNOT(what, args)        ASSERTPRINT(((!CapsLockCurrentlyDown()) && (what)), args)
  58.  
  59. #define BLOCKASSERTPRINT(what, args)    { if (!(what)) { dbgAssertPrint args; } }
  60. #define ASSERTPRINT(what, args)            do BLOCKASSERTPRINT(what, args) while (0)
  61. #define CAPSASSERTPRINT(what, args)        ASSERTPRINT(!CapsLockCurrentlyDown() || (what), args)
  62.  
  63. #define BLOCKASSERT(what)                { if (!(what)) dbgAssert(__FILE__,__LINE__); }
  64. #define    ASSERT(what)                    do BLOCKASSERT(what) while(0)
  65. #define    CAPSASSERT(what)                ASSERT(!CapsLockCurrentlyDown() || (what))
  66.  
  67. #define    ASSERTNOERR(what)                ASSERT((what) == noErr)
  68. #define    CAPSASSERTNOERR(what)            ASSERT(!CapsLockCurrentlyDown() || ((what) == noErr))
  69.  
  70.  
  71. #define BLOCKGUARD(object, className)    { if (!((object) && (object)->DerivedFrom(className))) dbgGuard(__FILE__,__LINE__); }
  72. #define    GUARD(object, className)        do BLOCKGUARD(object, className) while (0)
  73.  
  74. #define BLOCKREQUIREVALIDPOINTER(ptr)    { dbgInvalidPointer(ptr, __FILE__,__LINE__); }
  75. #define    REQUIREVALIDPOINTER(ptr)        do BLOCKREQUIREVALIDPOINTER(ptr) while (0)
  76.  
  77. #define BLOCKREQUIREVALIDHANDLE(handle)    { dbgInvalidHandle(handle, __FILE__,__LINE__); }
  78. #define    REQUIREVALIDHANDLE(handle)        do BLOCKREQUIREVALIDHANDLE(handle) while (0)
  79.  
  80.  
  81. // use to catch bad method calls
  82.  
  83. #define ABSTRACTBASE() ASSERT(false)
  84.  
  85. #else // DEBUG
  86.  
  87. // non-debug versions
  88.  
  89. #define INLINEASSERT(what)
  90.  
  91. #define    INITIALIZEDEBUG()
  92. #define TERMINATEDEBUG()
  93. #define    DEBUGEVENT(event)
  94.  
  95. #define MEASUREBLOCK()
  96. #define MEASUREPERFORMANCE()
  97. #define PERFORMANCEON()
  98. #define PERFORMANCEOFF()
  99.  
  100. #define BLOCKPRINT(args)                {}
  101. #define    PRINT(args)                        ((void)0)
  102. #define    CAPSPRINT(args)                    ((void)0)
  103.  
  104. #define BLOCKPRINTNOT(what, args)        {}
  105. #define    PRINTNOT(what,args)                ((void)0)
  106. #define    CAPSPRINTNOT(what,args)            ((void)0)
  107.  
  108. #define BLOCKASSERTPRINT(what, args)    {}
  109. #define    ASSERTPRINT(what,args)            ((void)0)
  110. #define    CAPSASSERTPRINT(what,args)        ((void)0)
  111.  
  112. #define BLOCKASSERT(what)                {}
  113. #define    ASSERT(what)                    ((void)0)
  114. #define    CAPSASSERT(what)                ((void)0)
  115.  
  116. #define    ASSERTNOERR(what)                ((void)0)
  117. #define    CAPSASSERTNOERR(what)            ((void)0)
  118.  
  119. #define BLOCKGUARD(object, className)    {}
  120. #define    GUARD(object, className)        ((void)0)
  121.  
  122. #define BLOCKREQUIREVALIDPOINTER(ptr)    {}
  123. #define    REQUIREVALIDPOINTER(ptr)        ((void)0)
  124.  
  125. #define BLOCKREQUIREVALIDHANDLE(handle)    {}
  126. #define    REQUIREVALIDHANDLE(handle)        ((void)0)
  127.  
  128. #define ABSTRACTBASE()                    ((void)0)
  129.  
  130. #endif // DEBUG
  131.  
  132. #endif // debug_h
  133.  
  134.